package com.xoa.controller.hr;

import com.xoa.model.common.HrCode;
import com.xoa.model.hr.HrStaffIncentive;
import com.xoa.model.hr.HrStaffIncentiveWithBLOBs;
import com.xoa.service.hr.HrStaffIncentiveService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.dataSource.ContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;


import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by 张丽军 on 2018/6/28.
 */
@Controller
@RequestMapping("/Hr/Incentive")
public class HrStaffIncentiveContorller {

    @Resource
    HrStaffIncentiveService hrStaffIncentiveService;

    //主页面
    @RequestMapping("/bonpenManagement")
    public String bonpenManagement(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/bonusPenalty/bonpenManagement";
    }
    //奖惩信息管理
    @RequestMapping("/bonpenManage")
    public String bonpenManage(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/bonusPenalty/bonpenManage";
    }
    //新建奖惩信息
    @RequestMapping("/bonpenNewedit")
    public String bonpenNewedit(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/bonusPenalty/bonpenNewedit";
    }
    //奖惩信息查询
    @RequestMapping("/bonpenQuery")
    public String bonpenQuery(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/bonusPenalty/bonpenQuery";
    }
    //奖惩信息导入
    @RequestMapping("/bonpenExport")
    public String bonpenExport(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/bonusPenalty/bonpenExport";
    }
	
	//奖惩信息详情页面
    @RequestMapping("/bonpenDetail")
    public String bonpenDetail(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/bonusPenalty/bonpenDetail";
    }

//    考试奖惩首页
    @RequestMapping("/bonpenManagements")
    public String bonpenManagements(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/examaination/bonpenManagement";
    }
//    考试奖惩列表页
@RequestMapping("/bonpenManages")
public String bonpenManages(HttpServletRequest request) {
    Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
    return "app/hr/examaination/bonpenManage";
}
//      考试奖惩新建页
@RequestMapping("/bonpenNewedits")
public String bonpenNewedits(HttpServletRequest request) {
    Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
    return "app/hr/examaination/bonpenNewedit";
}

    /**
     * 新建奖惩信息
     * @return
     */
    @ResponseBody
    @RequestMapping("/addHrIncentive")
    public ToJson<HrStaffIncentive> addHrIncentive(HttpServletRequest request,HrStaffIncentiveWithBLOBs hrStaffIncentiveWithBLOBs){
        return hrStaffIncentiveService.addHrIncentive(request,hrStaffIncentiveWithBLOBs);
    }

    /**
     * 更新奖惩信息
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateHrIncentive")
    public ToJson<HrStaffIncentive> updateHrIncentive(HttpServletRequest request,HrStaffIncentiveWithBLOBs hrStaffIncentiveWithBLOBs){
        return hrStaffIncentiveService.updateHrIncentive(request,hrStaffIncentiveWithBLOBs);
    }

    /**
     *查看奖惩信息详情
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectById")
    public ToJson<HrStaffIncentive> selectById(HttpServletRequest request,Integer incentiveId){
        return hrStaffIncentiveService.selectById(request,incentiveId);
    }

    /**
     *奖惩信息删除接口(可以多条删除)
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteById")
    public ToJson<HrStaffIncentive> deleteById(HttpServletRequest request,String incentiveId){
        return hrStaffIncentiveService.deleteById(request,incentiveId);
    }

    /**
     *奖惩信息列表接口
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/selectList")
    public ToJson<HrStaffIncentive> selectList(HttpServletRequest request, HttpServletResponse response, String staffName, String beginDate, String endTime, String incentiveItem, String incentiveType, Integer page, Integer pageSize, boolean useFlag, String export){
        return hrStaffIncentiveService.selectList(request,response,staffName,beginDate,endTime,incentiveItem,incentiveType,page,pageSize,useFlag,export);
    }
    /**
     * 导入奖惩信息
     * @param request
     * @param response
     * @param file
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/importIncentiveInfo", produces = {"application/json;charset=UTF-8"})
    public ToJson<HrStaffIncentive> importIncentiveInfo(HttpServletRequest request, HttpServletResponse response, MultipartFile file) {
        return hrStaffIncentiveService.importIncentiveInfo(request,response,file);
    }

    @RequestMapping("/getHrCodes")
    @ResponseBody
    public  ToJson<HrCode> getHrCodes(String type) {
        return hrStaffIncentiveService.getHrCodes(type);
    }

}
